using System;
using System.Text.RegularExpressions;

namespace Asah.SiteWorx.Search
{
	/// <summary>
	/// Summary description for CleanHtml.
	/// </summary>
	public class CleanHtml
	{
		public CleanHtml()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public static string Clean(string Contents)
		{
			if( Contents.IndexOf("startnav") != -1)
			{
				int startnav = Contents.IndexOf("startnav");
				int endnav = Contents.IndexOf("endnav");
				int lengthnav = endnav - startnav;
				string subContents = Contents.Substring(startnav, lengthnav);
				Contents = Contents.Replace(subContents, "");
			}
			Contents = Regex.Replace(Contents, "<(select|option|script|style|title)(.*?)>((.|\n)*?)</(select|option|script|style|title)>", " ", RegexOptions.IgnoreCase);
			Contents = Regex.Replace(Contents, "&(nbsp|quot|copy);", "");
			//Contents = regexp.Replace(Contents, "<[^>]*>", "");
			Contents = Regex.Replace(Contents, "<([\\s\\S])+?>", " ", RegexOptions.IgnoreCase).Replace("  ", " ");
			//Contents = regexp.Replace(Contents, "<[^<>]+>", " ", RegexOptions.IgnoreCase);
			//Contents = regexp.Replace("(<(\w+)[^>]*?>(.*?)</\1>", "$1");
			Contents = Regex.Replace(Contents, "\\W", " ");
			//Trace.Warn("File Contents", Contents);
			return Contents;
		}
	}
}
